package com.sqly.doc.util;

import android.os.Environment;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;

/**
 * Created by admin on 2018/5/28.
 */

public class SDCardUtil {
    private static String appFilePath = Environment.getExternalStorageDirectory().getPath()
            + File.separator + "Lude" + File.separator;
    //创建文件夹并写入数据
    public static  void CreatFileText(String str,String filename) {
        BufferedWriter writer ;
        File dataDir = new File(appFilePath );
        if (!dataDir.exists())
            dataDir.mkdirs();
        String path= dataDir.getAbsoluteFile() + "/"+filename+".txt";
        File file2 = new File(path) ;
        if (!file2.exists()) {
            try {
                file2.createNewFile();
            } catch (IOException e) {


            }
        }
        try {
            FileOutputStream out = new FileOutputStream(file2,true);
            writer = new BufferedWriter(new OutputStreamWriter(out)) ;
            writer.write(str) ;
            writer.close() ;
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
    public static boolean delFile(){
        File file = new File(appFilePath + "scian.txt");
        if(file.isFile()){
            file.delete();
        }
        return file.exists();
    }

}
